<template>
  <view class="container">
    <!-- 搜索框 -->
    <view class="fixed-box">
      <view class="search-bar">
        <view class="search-box">
          <input class="sear-input"  confirm-type="search" @confirm="doSearch"
          v-model="prodName"/>
          <image src="../../static/images/icon/search.png" class="search-img" />
        </view>
        <view class="search-list-img">
          <image
            v-if="showType == 1"
            @click="arrangement(2)"
            src="../../static/images/icon/search-col.png"
          />
          <image
            v-if="showType == 2"
            @click="arrangement(1)"
            src="../../static/images/icon/search-col2.png"
          />
        </view>
      </view>
      <!-- tab切换 -->
      <view class="tabs">
        <text
          class="tab-item complete"
          :id="sts == 0 ? 'on' : ''"
          data-sts="0"
          @click="onSort(0)"
          >综合</text
        >
        <text
          class="tab-item"
          :id="sts == 1 ? 'on' : ''"
          data-sts="1"
          @click="onSort(1)"
          >销量</text
        >
        <text
          class="tab-item"
          :id="sts == 2 ? 'on' : ''"
          data-sts="2"
          @click="onSort(2)"
          >价格</text
        >
      </view>
    </view>

    <!-- 商品列表 -->
    <view class="prod-list">
      <!-- 横向列表 -->
      <view class="prod-show" v-if="showType == 1">
        <view class="hotsale-item-cont">
          <block v-for="(item, index) in searchList" :key="index" :for-item="prod">
            <view
              class="prod-items"
              bindtap="toProdPage"
              :data-prodid="item.prodId"
            >
              <view class="hot-imagecont">
                <image :src="item.pic" class="hotsaleimg"></image>
              </view>
              <view class="hot-text">
                <view class="hotprod-text">{{ item.prodName }}</view>
                <view class="prod-info">{{ item.brief }}</view>
                <view class="prod-text-info">
                  <view class="prod-price more">
                    <text class="symbol">￥</text>
                    <text class="big-num">{{ item.price }}</text>
                    <!-- <text class='small-num'>.{{wxs.parsePrice(prod.price)[1]}}</text> -->
                  </view>
                  <image
                    src="../../static/images/tabbar/basket-sel.png"
                    class="basket-img"
                  ></image>
                </view>
              </view>
            </view>
          </block>
        </view>
      </view>

      <!-- 纵向列表 -->
      <view class="cont-item" v-if="showType == 2">
        <block v-for="(item, index) in searchList" :key="index">
          <view class="show-item" :data-prodid="item.prodId">
            <view class="more-prod-pic">
              <image :src="item.pic" class="more-pic"></image>
            </view>
            <view class="prod-text-right">
              <view class="prod-text more">{{ item.prodName }}</view>
              <view class="cate-prod-info"
                >{{ item.praiseNumber }}评价
                {{ item.positiveRating }}%好评</view
              >
              <view class="prod-price more">
                <text class="symbol">￥</text>
                <text class="big-num">{{ item.price }}</text>
              </view>
            </view>
          </view>
        </block>
      </view>
    </view>
  </view>
</template>

<script>
import { mapState, mapActions } from "vuex";

export default {
  data() {
    return {
      sts: 0,
      showType: 2,
      searchProdList: [],
      prodName: "",
    };
  },
  onLoad: function (options) {
    this.prodName = options.value;
  },
  onShow() {
    this.getSearchList({ prodName: this.prodName, sts: this.sts });
  },
  methods: {
    ...mapActions({
      getSearchList: "prodShow/getSearchList",
    }),
    // 排序方式的切换
    onSort(index) {
      this.sts = index;
      this.getSearchList({ prodName: this.prodName, sts: index });
    },
    // 商品列表样式的切换
    arrangement(index) {
      this.showType = index;
    },
    doSearch(){
      this.getSearchList({ prodName: this.prodName, sts: this.sts });
    }
  },
  computed: {
    ...mapState('prodShow',['searchList','hotSearchList']),
  },
};
</script>

<style>
/* 搜索栏 */

.fixed-box {
  position: fixed;
  width: 100%;
  top: 0;
  z-index: 999;
  background: #fff;
}

.search-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  color: #777;
  background: #fff;
  z-index: 3;
  padding: 0 30rpx;
  box-sizing: border-box;
}

.search-bar .search-box {
  position: relative;
  height: 60rpx;
  background: #f7f7f7;
  z-index: 999;
  width: 80%;
  border-radius: 50rpx;
  margin-right: 30rpx;
  flex: 1;
}

.sear-input {
  height: 60rpx;
  border-radius: 50rpx;
  border: 0;
  margin: 0 30rpx 0 64rpx;
  line-height: 48rpx;
  vertical-align: top;
  background: #f7f7f7;
  font-size: 28rpx;
}

.search-bar .search-hint {
  font-size: 28rpx;
  position: absolute;
  right: 30rpx;
  top: 31rpx;
  color: #eb2444;
}

.search-bar .search-box .search-img {
  width: 32rpx;
  height: 32rpx;
  position: absolute;
  left: 20rpx;
  top: 14rpx;
  display: block;
}

.search-bar .search-list-img {
  width: 40rpx;
  height: 40rpx;
  font-size: 0;
}

.search-bar .search-list-img image {
  width: 100%;
  height: 100%;
}

.fixed-box .tabs {
  width: 100%;
  height: 80rpx;
  line-height: 80rpx;
  padding: 10rpx 0;
  z-index: 999;
  background: #fff;
}

.fixed-box .tabs::after {
  content: "";
  background-color: #e1e1e1;
  left: 0;
  height: 1px;
  transform-origin: 50% 100% 0;
  bottom: 0;
  position: absolute;
  display: block;
  width: 100%;
}

.fixed-box .tabs .tab-item {
  display: inline-block;
  width: 33.33%;
  text-align: center;
  font-size: 28rpx;
}

#on {
  color: #eb2444;
}

/* 横向列表 */

.prod-show {
  background: #fff;
  margin-top: 160rpx;
}

.prod-show .prod-items {
  width: 375rpx;
  float: left;
  background: #fff;
  padding-bottom: 20rpx;
  box-sizing: border-box;
}

/* 纵向列表 */

.prod-list .cont-item {
  padding: 0 20rpx 20rpx 20rpx;
  margin-top: 180rpx;
}

.prod-list .cont-item .show-item .more-prod-pic {
  text-align: center;
  width: 170rpx;
  height: 170rpx;
  font-size: 0;
}

.prod-list .cont-item .show-item .more-prod-pic .more-pic {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

.prod-list .cont-item .show-item {
  position: relative;
  display: flex;
  justify-content: start;
  padding: 20rpx;
  border-radius: 20rpx;
  background: #fff;
  margin-bottom: 20rpx;
  box-shadow: 0 16rpx 32rpx 0 rgba(7, 17, 27, 0.05);
}

.prod-list .cont-item .show-item .prod-text-right {
  margin-left: 20rpx;
  width: 75%;
}

.prod-list .cont-item .show-item .prod-text-right .cate-prod-info {
  font-size: 22rpx;
  color: #999;
  margin: 10rpx 0 20rpx 0;
}

.prod-list .cont-item .show-item .prod-text-right .go-to-buy {
  font-size: 26rpx;
  background: #eb2444;
  color: #fff;
  border-radius: 50rpx;
  width: 150rpx;
  text-align: center;
  padding: 8rpx 3rpx;
  position: absolute;
  right: 20rpx;
  bottom: 20rpx;
}

.prod-list .cont-item .show-item .prod-text-right .prod-text.more {
  margin: 0;
  height: 78rpx;
  font-size: 28rpx;
  display: -webkit-box;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #000;
}

.prod-list .cont-item .show-item .prod-text-right .prod-price.more {
  font-size: 28rpx;
  color: #eb2444;
  font-family: arial;
}

.hot-sale .prod-items {
  width: 345rpx;
  display: inline-block;
  background: #fff;
  padding-bottom: 20rpx;
  box-sizing: border-box;
  /* border: 2rpx solid #e1e1e1; */
  box-shadow: 0rpx 6rpx 8rpx rgba(58, 134, 185, 0.2);
}

.hot-sale .prod-items:nth-child(2n-1) {
  margin: 20rpx 10rpx 10rpx 20rpx;
}

.hot-sale .prod-items:nth-child(2n) {
  margin: 20rpx 20rpx 10rpx 10rpx;
}

.prod-items .hot-imagecont .hotsaleimg {
  width: 341rpx;
  height: 341rpx;
}

.prod-items .hot-text .hotprod-text {
  font-size: 28rpx;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prod-items .hot-imagecont {
  font-size: 0;
  text-align: center;
}

.prod-items .hot-text {
  margin-top: 20rpx;
  padding: 0 10rpx;
}

.prod-items .hot-text .prod-info,
.more-prod .prod-text-right .prod-info {
  font-size: 22rpx;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prod-items .hot-text .prod-text-info {
  position: relative;
  height: 70rpx;
  line-height: 70rpx;
  font-family: Arial;
}

.prod-items .hot-text .prod-text-info .hotprod-price {
  display: inline;
  font-size: 26rpx;
  color: #eb2444;
}

.prod-items .hot-text .prod-text-info .basket-img {
  width: 50rpx;
  height: 50rpx;
  position: absolute;
  right: 0;
  bottom: 7rpx;
  padding: 8rpx;
}

.singal-price {
  display: inline;
  font-size: 20rpx;
  text-decoration: line-through;
  color: #777;
  margin-left: 15rpx;
}

</style>
